﻿using LitJson;
using LNet;
using OestsCommon.Model;
using OestsDataBase;
using OestsServer.Net;
using System.Collections.Generic;

namespace OestsServer.Handlers.OESPHandlers
{
    public class AddStudentHandler : HandlerBase<OESPClientChannel>
    {
        public override PacketKey PKey => PacketKey.AddStudent;
        public override void Execute(OESPClientChannel client, Request resquestPacket)
        {
            base.Execute(client, resquestPacket);
            List<Student> users = JsonMapper.ToObject<List<Student>>(resquestPacket.DataStr);
            bool res = UserDAL.AddStudents(ref users);
            if (res)
                ResponsePacket.ReturnCode = ReturnCode.Success;
            else
                ResponsePacket.ReturnCode = ReturnCode.Fail;
            ResponsePacket.DataObject = users;
            client.Send(ResponsePacket);
        }
    }

}